<template>
  <div>
    <FormPanel ref="formPanel" :list="formList" :formType="type" @formChange="formChangeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="115" />
    <FormPanel ref="formPanel1" :list="formList1" :formType="type" @formChange="formChangeHandle1" :isSubmitBtn="false" :collapse="false" labelWidth="110" />
    <FormPanel ref="formPanel2" :list="formList2" :formType="type" @formChange="formChangeHandle2" :isSubmitBtn="false" :collapse="false" labelWidth="110" />
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'center'
      }"
    >
      <multiuse-button v-show="type != 'show' && !this.isApply" type="primary" :disabled="isApply" :click="dataHandle.bind(this, 3)">申请结束犹豫期</multiuse-button>
      <multiuse-button v-show="type != 'show'" type="primary" :disabled="isDisabled" :click="dataHandle.bind(this, 1)">提 交</multiuse-button>
      <multiuse-button v-show="type != 'show'" type="primary" :disabled="isSave" :click="dataHandle.bind(this, 2)">保 存</multiuse-button>
      <el-button @click="closeDrawer">返 回</el-button>
    </div>

    <BaseDialog :visible.sync="isShowCstmr" :title="'潜客信息'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <SearchCstmr :rowData="formData" @close="closeDialog" />
    </BaseDialog>

    <BaseDialog :visible.sync="isShowCode" :title="'产品信息'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <SearchCode :rowData="formData" @close="closeDialog1" />
    </BaseDialog>

    <BaseDialog :visible.sync="isShowVin" :title="'物料信息'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <SearchVin :rowData="formData" @close="closeDialog2" />
    </BaseDialog>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { getEmployees, applyCloseTheDate, queryRetailOrderById, saveOrder, commitOrder } from '@/api/dealerSale/SalesSanagement/RetailOrderMaintenanceAF';
import SearchCstmr from './SearchCstmr';
import SearchCode from './SearchCode';
import SearchVin from './SearchVin';
import { getLoginUser } from '@/api/cms-api/projectOperating/program/departmentInquire'; //获取登录信息

import { banWord, phone, plus, IDNumber } from '@/utils/validate';
import { getUserByIdCMSNew } from '@/api/common/auth/roleManage';
import { getUserOrgId, getUserId } from '@/assets/js/auth';
export default {
  mixins: [dictionary],

  props: {
    type: {
      type: String,
      default: 'show'
    },
    rowData: {
      type: Object,
      default: () => ({})
    }
  },
  components: {
    SearchCstmr,
    SearchCode,
    SearchVin
  },
  data() {
    this.saveData = null;
    this.saveData1 = null;
    this.saveData2 = null;
    return {
      formList: this.createdFrom(),
      formList1: this.createdFrom1(),
      formList2: this.createdFrom2(),
      selectData: [],
      isShowCstmr: false,
      isShowCode: false,
      isShowVin: false,
      formData: {},
      editData: {},
      detailData: {},
      cstmrData: null,
      vinData: null,
      codeData: null,
      isApply: true,
      isDisabled: true,
      isSave: true,
      empList: [],
      salesManId: ''
    };
  },
  mounted() {
    this.init();
    // this.queryEmployees();
    this.queryUserById();
    this.getDealerName();
  },
  methods: {
    init() {
      if (this.type != 'add') {
        this.getInfoById();
      } else {
        this.isSave = false;
      }
      if (this.type == 'show') {
        this.formList.map(x => {
          x.placeholder = '';
          if (x.rules) {
            x.rules[0].required = false;
          }
        });

        this.formList1.map(x => {
          x.placeholder = '';
          if (x.rules) {
            x.rules[0].required = false;
          }
        });

        this.formList2.map(x => {
          x.placeholder = '';
          if (x.rules) {
            x.rules[0].required = false;
          }
        });
      }
    },
    // 翻译ID
    transDictText(val, dirtArr) {
      let res = '';
      if (!val) return res;
      if (Array.isArray(dirtArr)) {
        const target = dirtArr.find(x => x.value == val);
        res = target ? target.text || '' : val;
      }
      return res;
    },
    // 获取登录信息
    async getDealerName() {
      const res = await getLoginUser();
      if (res.resultCode == 200) {
        this.formList.find(x => x.fieldName == 'dealerName').initialValue = res.data.dealerName;
      }
    },
    async queryUserById() {
      let userId = getUserId();
      let userOrgId = getUserOrgId();
      const res = await getUserByIdCMSNew({ userId: userId, userOrgId: userOrgId });
      if (res.resultCode === 200) {
        // if (null != res.data.positionCode && -1 != res.data.positionCode.search('10061015')) {
        this.salesManId = res.data.userId;
        this.formList.find(item => item.fieldName == 'salesManName').initialValue = res.data.userName;
        // }
      }
    },
    // 查询销售顾问
    async queryEmployees() {
      const res = await getEmployees();
      if (res.resultCode == 200) {
        res.data.map(x => {
          this.empList.push({ text: x.userName, value: x.userId });
          // this.formList.find(item => item.fieldName == 'salesManId').itemList.push({ text: x.userName, value: x.userId });
        });
      }
    },

    // 根据ID查详细
    async getInfoById() {
      const res = await queryRetailOrderById(this.rowData.orderId);
      if (res.resultCode == 200) {
        this.detailData = res.data;
        res.data.isHesitationPeriod == 10041001 ? (this.isApply = false) : (this.isApply = true);
        res.data.isHesitationPeriod != 10041001 ? (this.isSave = false) : (this.isSave = true);
        res.data.orderVinShowDto && res.data.isHesitationPeriod != 10041001 ? (this.isDisabled = false) : (this.isDisabled = true);
        // 1、零售信息
        this.formList.map(x => {
          // 潜客信息替换页面信息vsCustomerDTO 客户编号、客户姓名、手机号、证件类型、证件号、省市区、联系地址
          if (
            x.fieldName == 'customerNo' ||
            x.fieldName == 'customerName' ||
            x.fieldName == 'customerType' ||
            x.fieldName == 'customerPhone' ||
            x.fieldName == 'cardType' ||
            x.fieldName == 'cardNo' ||
            x.fieldName == 'provinceId' ||
            x.fieldName == 'cityId' ||
            x.fieldName == 'districtId' ||
            x.fieldName == 'linkAddress'
          ) {
            let data = res.data.vsCustomerDTO;
            this.formList.find(x => x.fieldName == 'cityId').itemList = this.createcityList(data.provinceId);
            this.formList.find(x => x.fieldName == 'districtId').itemList = this.district(data.cityId);
            if (x.fieldName == 'customerPhone') {
              x.initialValue = data['mobile'];
            } else {
              x.initialValue = data[x.fieldName];
              this.changeCardType(data['cardType'], 1);
            }

            if (data['customerType'] == 15231003) {
              this.formList.find(x => x.fieldName == 'enterpriseName').rules[0].required = true;
              this.formList.find(x => x.fieldName == 'taxpayerNumer').rules[0].required = true;
            }
            if (data['customerType'] == 15231001) {
              this.formList.find(x => x.fieldName == 'cardType').rules[0].required = true;
              this.formList.find(x => x.fieldName == 'cardNo').rules[0].required = true;
            }
          } else if (x.fieldName == 'isIntentionMoney' || x.fieldName == 'intentionMoney' || x.fieldName == 'isLargeFixedAmount' || x.fieldName == 'largeFixedAmount') {
            x.initialValue = res.data[x.fieldName];
            // 线上单子并且大定交了都置灰；没交大定可编辑
            if (10041001 == res.data.isJihuApp && 10041001 == res.data.isLargeFixedAmount) {
              x.disabled = true;
              return;
            }

            if (10041001 == res.data.isLargeFixedAmount) {
              x.disabled = true;
              return;
            }
            if (10041001 == res.data.isIntentionMoney) {
              if (x.fieldName == 'isIntentionMoney' || x.fieldName == 'intentionMoney') x.disabled = true;
              return;
            }
            x.disabled = false;
          } else if (x.fieldName == 'payType') {
            x.initialValue = res.data['payType'];
            if (res.data['payType'] == 60151001) {
              this.formList.find(x => x.fieldName == 'downPayment').rules[0].required = true;
              this.formList.find(x => x.fieldName == 'loanAmount').rules[0].required = true;
              return;
            }
          } else if (x.fieldName == 'isHesitationPeriod') {
            x.initialValue = res.data[x.fieldName] || 10041002;
          } else {
            x.initialValue = res.data[x.fieldName];
          }
        });
        // 2、车辆信息
        this.formList1.map(x => {
          let orderVinShowDto = res.data.orderVinShowDto || res.data;

          if (x.fieldName == 'salesQuatation') {
            x.initialValue = res.data['salesQuatation'];
          } else if (x.fieldName == 'discountAmount') {
            let result = 0;
            let basicPrice = orderVinShowDto.basicPrice;
            if (!basicPrice) return;
            result = parseFloat(basicPrice) - parseFloat(res.data.salesQuatation);
            x.initialValue = result || 0;
          } else if (x.fieldName == 'checkDesc') {
            x.initialValue = res.data['checkDesc'];
          } else {
            x.initialValue = orderVinShowDto[x.fieldName];
          }
        });
        // 3、指标人信息
        this.formList2.map(x => {
          if (res.data['indicatorType']) {
            x.initialValue = res.data[x.fieldName];
            this.changeCardType(res.data['indicatorCardType'], 2);
          }
          if (this.type == 'show') return;

          if (15231001 == res.data.indicatorType) {
            if (x.fieldName == 'indicatorName' || x.fieldName == 'indicatorCardType' || x.fieldName == 'indicatorCardNo') {
              x.rules[0].required = true;
              x.placeholder = '请输入';
              x.disabled = false;
            }
            if (x.fieldName == 'address' || x.fieldName == 'zipCode') {
              x.placeholder = '';
              x.disabled = false;
            }
            if (x.fieldName == 'indicatorEnterpriseName' || x.fieldName == 'creditCode') {
              x.rules[0].required = false;
              x.initialValue = '';
              x.placeholder = '';
              x.disabled = true;
            }
          }

          if (15231003 == res.data.indicatorType) {
            if (x.fieldName == 'indicatorName' || x.fieldName == 'indicatorCardType' || x.fieldName == 'indicatorCardNo') {
              x.rules[0].required = false;
              x.initialValue = '';
              x.placeholder = '';
              x.disabled = true;
            }

            if (x.fieldName == 'indicatorEnterpriseName' || x.fieldName == 'creditCode') {
              x.rules[0].required = true;
              x.placeholder = '请输入';
              x.disabled = false;
            }
            if (x.fieldName == 'address' || x.fieldName == 'zipCode') {
              x.placeholder = '请输入';
              x.disabled = false;
            }
          }
        });
      } else {
        this.$notify.error({ title: '提示信息', message: res.errMsg });
      }
    },
    formChangeHandle(val) {
      val.provinceName = this.createRegionsList().find(x => x.value == val.provinceId).text;
      val.cityName = this.createcityList(val.provinceId).find(x => x.value == val.cityId).text;
      val.districtName = this.district(val.cityId).find(x => x.value == val.districtId).text;
      this.saveData = val;
    },
    formChangeHandle1(val) {
      this.saveData1 = val;
    },
    formChangeHandle2(val) {
      this.saveData2 = val;
    },
    async dataHandle(type) {
      this.$refs.formPanel.SUBMIT_FORM();
      this.$refs.formPanel1.SUBMIT_FORM();
      this.$refs.formPanel2.SUBMIT_FORM();
      if (this.saveData !== null && this.saveData1 !== null && this.saveData2 !== null) {
        this.editData = {
          id: this.rowData.orderId || '',
          depositAmount: this.saveData.depositAmount || '',
          depositDate: this.saveData.depositDate || '',
          expectDate: this.saveData.expectDate || '',
          buyPurpose: this.saveData.buyPurpose || '',
          isMajor: this.saveData.isMajor || '',
          isSpecial: this.saveData.isSpecial || '',
          orderType: this.saveData.orderType || '',
          payType: this.saveData.payType || '',
          loanAmount: this.saveData.loanAmount || '',
          downPayment: this.saveData.downPayment || '',
          referencesName: this.saveData.referencesName || '',
          referencesPhone: this.saveData.referencesPhone || '',
          verificationCode: this.saveData.verificationCode || '',
          isIntentionMoney: this.saveData.isIntentionMoney || '',
          enterpriseName: this.saveData.enterpriseName || '',
          taxpayerNumer: this.saveData.taxpayerNumer || '',
          intentionMoney: this.saveData.intentionMoney || '',
          isLargeFixedAmount: this.saveData.isLargeFixedAmount || '',
          largeFixedAmount: this.saveData.largeFixedAmount || '',
          isJihuApp: this.saveData.isJihuApp || 10041002,
          isHesitationPeriod: this.saveData.isHesitationPeriod || 10041002,
          remark: this.saveData.remark || '',
          salesManId: this.salesManId || '',
          salesManName: this.saveData.salesManName || '',
          signDate: this.saveData.signDate || '',
          vehicleId: this.vinData != null ? this.vinData.vehicleId : this.detailData.orderVinShowDto ? this.detailData.orderVinShowDto.vehicleId : '',
          productCode: this.saveData1.productCode || '',
          salesQuatation: this.saveData1.salesQuatation || '',
          vsCustomerDTO: {
            bussinessId: this.cstmrData ? this.cstmrData.costomerBusinessId : this.detailData.vsCustomerDTO.bussinessId,
            cardNo: this.saveData.cardNo || '',
            cardType: this.saveData.cardType || '',
            customerName: this.saveData.customerName || '',
            customerNo: this.saveData.customerNo || '',
            mobile: this.saveData.customerPhone || '',
            linkAddress: this.saveData.linkAddress || '',
            customerType: this.cstmrData ? this.cstmrData.customerType : this.detailData.vsCustomerDTO.customerType,
            customerSex: this.cstmrData ? this.cstmrData.gender : this.detailData.vsCustomerDTO.customerSex,
            potentCustomerId: this.cstmrData ? this.cstmrData.potentialCustomersId : this.detailData.vsCustomerDTO.potentCustomerId
          },
          orderVinShowDto: {},
          ...this.saveData2
        };
        // 潜客信息
        this.editData.vsCustomerDTO = Object.assign(this.editData.vsCustomerDTO, this.saveData);
        // 车辆信息
        this.editData.orderVinShowDto = Object.assign(this.editData.orderVinShowDto, this.saveData1);
        // 保存的数据
        let saveData = Object.assign(this.detailData, this.editData);

        console.log(saveData, '---表单的数据---');
        let res = {};
        if (type == 1) {
          // 提交
          res = await commitOrder(saveData);
        }
        if (type == 2) {
          // 保存
          res = await saveOrder(saveData);
        }
        if (type == 3) {
          // 结束犹豫
          res = await applyCloseTheDate(saveData);
        }
        if (res.resultCode === 200) {
          if (res.data && 1 == res.data.code) {
            this.$notify.success({ title: '提示信息', message: type == 3 ? '操作成功，请耐心等待申请结果！' : `${type == 1 ? '提交' : '保存'}成功！` });
            this.closeDrawer('refresh');
            return;
          }

          if (res.data && 0 == res.data.code) {
            this.$notify.warning({ title: '提示信息', message: res.data.message ? res.data.message : '操作失败，请稍后再试！' });
            return;
          }
          // this.$notify.error({ title: '提示信息', message: res.data.message ? res.data.message : '操作失败，请稍后再试！' });
          this.$notify.success({ title: '提示信息', message: type == 3 ? '操作成功，请耐心等待申请结果！' : `${type == 1 ? '提交' : '保存'}成功！` });
          this.closeDrawer('refresh');
        } else {
          this.$notify.error({ title: '提示信息', message: res.errMsg });
        }
      }
    },
    closeDrawer(type) {
      this.$emit('close', false, type);
    },
    // 查询潜客
    cstmrNoHandle() {
      this.isShowCstmr = true;
    },
    // 查询产品
    codeHandle() {
      this.isShowCode = true;
    },
    closeDialog(val, data) {
      this.isShowCstmr = val;
      if (data) {
        this.cstmrData = data[0];
        this.setFormData(data[0]);
      }
      console.log(data, '---关闭潜客---');
    },
    closeDialog1(val, data) {
      this.isShowCode = val;
      if (data) {
        data[0].basicPrice = data[0].oemDirectivePrice || '';
        this.codeData = data[0];
        this.setFormData1(data[0]);
      }
      console.log(data, '---关闭产品代码---');
    },
    closeDialog2(val, data) {
      this.isShowVin = val;
      if (data) {
        this.vinData = data[0];
        this.setFormData1(data[0]);
      }
      console.log(data, '---关闭VIN---');
    },
    setFormData(data) {
      for (let key in data) {
        this.formList.map(x => {
          if (x.fieldName == 'customerNo') {
            x.initialValue = data['potentialCustomerNo'];
          }
          if (x.fieldName == 'customerName') {
            x.initialValue = data['customerName'];
          }
          if (x.fieldName == 'customerType') {
            x.initialValue = data['customerType'];
          }
          if (data['customerType'] == 15231003 && (x.fieldName == 'enterpriseName' || x.fieldName == 'taxpayerNumer')) {
            x.rules[0].required = true;
          }
          if (x.fieldName == 'customerPhone') {
            x.initialValue = data['mobilePhone'];
          }
          if (x.fieldName == 'cardType') {
            x.initialValue = data['ctCode'];
            this.changeCardType(data['ctCode']);
          }
          if (x.fieldName == 'cardNo') {
            x.initialValue = data['certificateNo'];
          }
          if (data['customerType'] == 15231001 && (x.fieldName == 'cardType' || x.fieldName == 'cardNo')) {
            x.rules[0].required = true;
          }
          if (x.fieldName == 'provinceId') {
            x.initialValue = data['province'] ? Number(data['province']) : '';
          }
          if (x.fieldName == 'cityId') {
            x.initialValue = data['city'] ? Number(data['city']) : '';
            x.itemList = this.createcityList(data.province);
          }
          if (x.fieldName == 'districtId') {
            x.initialValue = data['area'] ? Number(data['area']) : '';
            x.itemList = this.district(data.city);
          }
          if (x.fieldName == 'linkAddress') {
            x.initialValue = data['address'];
          }
        });
      }
    },
    setFormData1(data) {
      if (this.detailData.orderVinShowDto) this.detailData.orderVinShowDto.vehicleId = '';
      if (10041001 == this.formList.find(x => x.fieldName == 'isHesitationPeriod').initialValue) {
        this.isDisabled = true;
      } else {
        this.isDisabled = data.vin ? false : true; // 2021-4-17 12:38:58  qinjh 编辑更换产品代码，提交按钮先置灰
      }
      this.formList1.map(x => {
        x.initialValue = '';
      });
      for (let key in data) {
        this.formList1.map(x => {
          if (x.fieldName == key) {
            if (x.fieldName == 'salesQuatation') {
              x.initialValue = data['basicPrice'];
            } else if (x.fieldName == 'basicPrice') {
              if (data['basicPrice']) {
                x.initialValue = data['basicPrice'];
                let result = 0;
                let salesQuatation = data['basicPrice'];
                console.log(salesQuatation, '---salesQuatation---');
                result = parseFloat(data['basicPrice']) - parseFloat(salesQuatation);
                this.formList1.find(x => x.fieldName === 'discountAmount').initialValue = result || 0;
              }
            } else {
              x.initialValue = data[key];
            }
          }
        });
      }
    },
    // 查询VIN
    vinHandle() {
      this.isShowVin = true;
      this.formData.productCode = this.formList1.find(x => x.fieldName == 'productCode').initialValue;
    },

    setItems(val) {
      if (val == 15231001) {
        this.formList2.map(x => {
          if (x.fieldName == 'indicatorName' || x.fieldName == 'indicatorCardType' || x.fieldName == 'indicatorCardNo') {
            x.rules[0].required = true;
            x.placeholder = '请输入';
            x.disabled = false;
          }
          if (x.fieldName == 'address' || x.fieldName == 'zipCode') {
            x.placeholder = '请输入';
            x.disabled = false;
          }
          if (x.fieldName == 'indicatorEnterpriseName' || x.fieldName == 'creditCode') {
            x.rules[0].required = false;
            x.initialValue = '';
            x.placeholder = '';
            x.disabled = true;
          }
        });
        return;
      }
      if (val == 15231003) {
        this.formList2.map(x => {
          if (x.fieldName == 'indicatorName' || x.fieldName == 'indicatorCardType' || x.fieldName == 'indicatorCardNo') {
            x.rules[0].required = false;
            x.initialValue = '';
            x.placeholder = '';
            x.disabled = true;
          }

          if (x.fieldName == 'indicatorEnterpriseName' || x.fieldName == 'creditCode') {
            x.rules[0].required = true;
            x.placeholder = '请输入';
            x.disabled = false;
          }
          if (x.fieldName == 'address' || x.fieldName == 'zipCode') {
            x.placeholder = '请输入';
            x.disabled = false;
          }
        });
        return;
      }
      this.formList2.map(x => {
        if (x.fieldName == 'indicatorName' || x.fieldName == 'indicatorCardType' || x.fieldName == 'indicatorCardNo' || x.fieldName == 'indicatorEnterpriseName' || x.fieldName == 'creditCode') {
          x.rules[0].required = false;
          x.initialValue = '';
          x.placeholder = '';
          x.disabled = true;
        }
        if (x.fieldName == 'address' || x.fieldName == 'zipCode') {
          x.initialValue = '';
          x.placeholder = '';
          x.disabled = true;
        }
      });
    },

    //改变证件类型,证件类型为身份证的时候加校验
    changeCardType(val, idx = 1) {
      if (!val || this.type == 'show') return;
      if (2 != idx) {
        if (15081001 == val) {
          console.log('客户类型个人', '---奥利给---');
          this.formList.find(item => item.fieldName === 'cardNo').rules = [
            { required: true, message: '请输入证件号码', trigger: 'blur' },
            { trigger: 'blur', validator: IDNumber }
          ];
          return;
        }
        this.formList.find(item => item.fieldName === 'cardNo').rules = [
          { required: true, message: '请输入证件号码', trigger: 'blur' },
          { trigger: 'blur', validator: banWord }
        ];
        return;
      }
      if (15081001 == val) {
        this.formList2.find(item => item.fieldName === 'indicatorCardNo').rules = [
          { required: true, message: '请输入证件号码', trigger: 'blur' },
          { trigger: 'blur', validator: IDNumber }
        ];
        return;
      }
      this.formList2.find(item => item.fieldName === 'indicatorCardNo').rules = [
        { required: true, message: '请输入证件号码', trigger: 'blur' },
        { trigger: 'blur', validator: banWord }
      ];
    },
    createdFrom() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '零售信息'
        },
        {
          type: 'INPUT',
          label: '零售单号',
          fieldName: 'orderNo',
          placeholder: '自动生成',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '客户编号',
          fieldName: 'customerNo',
          placeholder: '',
          readonly: true,
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
          unitRender: () => {
            return <el-button slot="append" icon="el-icon-search" onClick={() => this.cstmrNoHandle()}></el-button>;
          }
        },
        {
          type: 'SELECT',
          label: '客户类型',
          fieldName: 'customerType',
          placeholder: '请选择',
          itemList: this.createDictList('1523'),
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
          change: val => {
            if (val == 15231001) {
              this.formList.find(x => x.fieldName == 'cardType').rules[0].required = true;
              this.formList.find(x => x.fieldName == 'cardNo').rules[0].required = true;
              this.formList.find(x => x.fieldName == 'enterpriseName').rules[0].required = false;
              this.formList.find(x => x.fieldName == 'taxpayerNumer').rules[0].required = false;
              return;
            }
            if (val == 15231003) {
              this.formList.find(x => x.fieldName == 'enterpriseName').rules[0].required = true;
              this.formList.find(x => x.fieldName == 'taxpayerNumer').rules[0].required = true;
              this.formList.find(x => x.fieldName == 'cardType').rules[0].required = false;
              this.formList.find(x => x.fieldName == 'cardNo').rules[0].required = false;
              return;
            }
            this.formList.find(x => x.fieldName == 'cardType').rules[0].required = false;
            this.formList.find(x => x.fieldName == 'cardNo').rules[0].required = false;

            this.formList.find(x => x.fieldName == 'enterpriseName').rules[0].required = false;
            this.formList.find(x => x.fieldName == 'taxpayerNumer').rules[0].required = false;
          }
        },
        {
          type: 'INPUT',
          label: '客户姓名',
          fieldName: 'customerName',
          placeholder: '请输入',
          rules: [{ required: true, message: '请输入', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '手机号',
          fieldName: 'customerPhone',
          placeholder: '请输入',
          rules: [
            { required: true, message: '请输入', trigger: 'blur' },
            {
              validator: phone,
              trigger: 'blur'
            }
          ]
        },
        {
          type: 'INPUT',
          label: '企业名称',
          fieldName: 'enterpriseName',
          placeholder: '请输入',
          rules: [{ required: false, message: '请输入', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '证件类型',
          fieldName: 'cardType',
          placeholder: '请选择',
          itemList: this.createDictList('1508'),
          rules: [{ required: false, message: '请选择', trigger: 'change' }],
          change: val => {
            if (val) {
              this.changeCardType(val);
            }
          }
        },
        {
          type: 'INPUT',
          label: '证件号',
          fieldName: 'cardNo',
          placeholder: '请输入',
          rules: [
            { required: false, message: '请输入证件号码', trigger: 'blur' },
            { trigger: 'blur', validator: banWord }
          ]
        },
        {
          type: 'INPUT',
          label: '纳税人识别号',
          fieldName: 'taxpayerNumer',
          placeholder: '请输入',
          rules: [{ required: false, message: '请输入', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '省份',
          fieldName: 'provinceId',
          placeholder: '请选择',
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
          itemList: this.createRegionsList(),
          change: p => {
            if (p) {
              this.formList.map(x => {
                if (x.fieldName == 'cityId') {
                  x.initialValue = '';
                  x.itemList = this.createcityList(p);
                }
              });
            } else {
              this.formList.map(x => {
                if (x.fieldName == 'cityId') {
                  x.itemList = [];
                  x.initialValue = '';
                }
                if (x.fieldName == 'districtId') {
                  x.itemList = [];
                  x.initialValue = '';
                }
              });
            }
          }
        },
        {
          type: 'SELECT',
          label: '城市',
          fieldName: 'cityId',
          placeholder: '请选择',
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
          itemList: [],
          change: p => {
            if (p) {
              this.formList.map(x => {
                if (x.fieldName == 'districtId') {
                  x.initialValue = '';
                  x.itemList = this.district(p);
                }
              });
            } else {
              this.formList.map(x => {
                if (x.fieldName == 'districtId') {
                  x.itemList = [];
                  x.initialValue = '';
                }
              });
            }
          }
        },
        {
          type: 'SELECT',
          label: '县区',
          fieldName: 'districtId',
          placeholder: '请选择',
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
          itemList: []
        },
        {
          type: 'INPUT',
          label: '联系地址',
          fieldName: 'linkAddress',
          placeholder: '请输入',
          selfCols: 2,
          rules: [{ required: true, message: '请输入', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '经销商',
          fieldName: 'dealerName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'SELECT',
          label: '购车用途',
          fieldName: 'buyPurpose',
          placeholder: '请选择',
          itemList: this.createDictList('1511')
        },
        {
          type: 'INPUT',
          label: '开单人',
          fieldName: 'sheetManName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'DATE',
          label: '签约日期',
          fieldName: 'signDate',
          dateType: 'exactdate',
          placeholder: '请选择'
        },
        {
          type: 'DATE',
          label: '预交车时间',
          fieldName: 'expectDate',
          dateType: 'exactdate',
          placeholder: '请选择'
        },
        {
          type: 'INPUT',
          label: '销售顾问',
          fieldName: 'salesManName',
          placeholder: '',
          disabled: true,
          rules: [{ required: true, message: '请输入', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '订单来源',
          fieldName: 'orderType',
          placeholder: '请选择',
          itemList: this.createDictList('6026'),
          rules: [{ required: true, message: '请选择', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '支付方式',
          fieldName: 'payType',
          placeholder: '请选择',
          itemList: this.createDictList('6015'),
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
          change: val => {
            if (val == 60151001) {
              this.formList.find(x => x.fieldName == 'downPayment').rules[0].required = true;
              this.formList.find(x => x.fieldName == 'loanAmount').rules[0].required = true;
              return;
            }
            this.formList.find(x => x.fieldName == 'downPayment').rules[0].required = false;
            this.formList.find(x => x.fieldName == 'loanAmount').rules[0].required = false;
          }
        },
        {
          type: 'INPUT',
          label: '首付款',
          fieldName: 'downPayment',
          maxlength: 9,
          placeholder: '请输入',
          rules: [
            { required: false, message: '请输入', trigger: 'blur' },
            {
              validator: plus,
              trigger: 'blur'
            }
          ]
        },
        {
          type: 'INPUT',
          label: '贷款金额',
          fieldName: 'loanAmount',
          maxlength: 9,
          placeholder: '请输入',
          rules: [
            { required: false, message: '请输入', trigger: 'blur' },
            {
              validator: plus,
              trigger: 'blur'
            }
          ]
        },
        {
          type: 'INPUT',
          label: '推荐人姓名',
          fieldName: 'referencesName',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '推荐人电话',
          fieldName: 'referencesPhone',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '核销码',
          fieldName: 'verificationCode',
          placeholder: '请输入'
        },
        {
          type: 'SELECT',
          label: '支付意向金',
          fieldName: 'isIntentionMoney',
          initialValue: 10041002,
          itemList: this.createDictList('1004'),
          change: val => {
            if (10041001 == val) {
              this.formList.find(x => x.fieldName == 'intentionMoney').rules[0].required = true;
              return;
            }
            this.formList.find(x => x.fieldName == 'intentionMoney').rules[0].required = false;
          }
        },
        {
          type: 'INPUT',
          label: '意向金金额',
          fieldName: 'intentionMoney',
          maxlength: 9,
          offsetRightCols: 1,
          placeholder: '请输入',
          rules: [
            { required: false, message: '请输入', trigger: 'blur' },
            {
              validator: plus,
              trigger: 'blur'
            }
          ]
        },
        {
          type: 'SELECT',
          label: '支付大定',
          fieldName: 'isLargeFixedAmount',
          initialValue: 10041002,
          itemList: this.createDictList('1004'),
          change: val => {
            if (10041001 == val) {
              this.formList.find(x => x.fieldName == 'largeFixedAmount').rules[0].required = true;
              this.formList.find(x => x.fieldName == 'isHesitationPeriod').initialValue = 10041001;
              this.isDisabled = true;

              return;
            }
            this.formList.find(x => x.fieldName == 'largeFixedAmount').rules[0].required = false;
            this.formList.find(x => x.fieldName == 'isHesitationPeriod').initialValue = 10041002;
            this.isDisabled = false;
          }
        },
        {
          type: 'INPUT',
          label: '大定金额',
          fieldName: 'largeFixedAmount',
          offsetRightCols: 1,
          maxlength: 9,
          placeholder: '请输入',
          rules: [
            { required: false, message: '请输入', trigger: 'change' },
            {
              validator: plus,
              trigger: 'blur'
            }
          ]
        },
        // {
        //   type: 'SELECT',
        //   label: '大客户订单',
        //   fieldName: 'isMajor',
        //   initialValue: 10041002,
        //   itemList: this.createDictList('1004'),
        //   rules: [{ required: true, message: '请选择', trigger: 'change' }]
        // },
        // {
        //   type: 'SELECT',
        //   label: '特殊订单',
        //   fieldName: 'isSpecial',
        //   initialValue: 10041002,
        //   offsetRightCols: 1,
        //   itemList: this.createDictList('1004'),
        //   rules: [{ required: true, message: '请选择', trigger: 'change' }]
        // },
        {
          type: 'SELECT',
          label: '极狐APP客户订单',
          fieldName: 'isJihuApp',
          initialValue: 10041002,
          disabled: true,
          itemList: this.createDictList('1004'),
          rules: [{ required: false, message: '请选择', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '是否在犹豫期内',
          fieldName: 'isHesitationPeriod',
          initialValue: 10041002,
          itemList: this.createDictList('1004'),
          offsetRightCols: 1,
          disabled: true,
          rules: [{ required: false, message: '请选择', trigger: 'change' }]
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'remark',
          selfCols: 3,
          placeholder: ''
        }
      ];
    },
    createdFrom1() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '车辆信息'
        },
        {
          type: 'INPUT',
          label: '产品代码',
          fieldName: 'productCode',
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
          readonly: true,
          unitRender: () => {
            return <el-button slot="append" icon="el-icon-search" onClick={() => this.codeHandle()}></el-button>;
          }
        },
        {
          type: 'INPUT',
          label: '产品名称',
          fieldName: 'productName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '品牌名称',
          fieldName: 'brandName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车系名称',
          fieldName: 'seriesName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车型名称',
          fieldName: 'modelName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '配置名称',
          fieldName: 'packageName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '选装名称',
          fieldName: 'optionName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '内饰',
          fieldName: 'trimColorName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '外色',
          fieldName: 'colorName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '',
          readonly: true,
          unitRender: () => {
            return <el-button slot="append" icon="el-icon-search" onClick={() => this.vinHandle()}></el-button>;
          }
        },
        {
          type: 'INPUT',
          label: '发动机号',
          fieldName: 'engineNo',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '电机号',
          fieldName: 'motorCode',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '电池号',
          fieldName: 'batteryNo',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '合格证号',
          fieldName: 'certificateNo',
          placeholder: '',
          offsetRightCols: 1,
          disabled: true
        },

        {
          type: 'INPUT',
          label: '销售指导价',
          fieldName: 'basicPrice',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '销售报价',
          fieldName: 'salesQuatation',
          placeholder: '请输入',
          maxlength: 9,
          rules: [
            { required: true, message: '请输入销售报价', trigger: 'blur' },
            {
              validator: plus,
              trigger: 'blur'
            }
          ],
          onInput: val => {
            if (val) {
              let result = 0;
              let basicPrice = this.formList1.find(x => x.fieldName === 'basicPrice').initialValue;
              if (!basicPrice) return;
              result = parseFloat(basicPrice) - parseFloat(val);
              this.formList1.find(x => x.fieldName === 'discountAmount').initialValue = result || 0;
              return;
            }
            this.formList1.find(x => x.fieldName === 'discountAmount').initialValue = '';
          }
        },
        {
          type: 'INPUT',
          label: '折让金额',
          fieldName: 'discountAmount',
          placeholder: '',
          disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '审批意见',
          fieldName: 'checkDesc',
          selfCols: 3,
          placeholder: '',
          disabled: true
        }
      ];
    },
    createdFrom2() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '指标人信息'
        },
        {
          type: 'SELECT',
          label: '指标人类型',
          fieldName: 'indicatorType',
          initialValue: '',
          offsetRightCols: 2,
          itemList: this.createDictList('1523'),
          rules: [{ required: false, message: '请选择', trigger: 'change' }],
          change: val => {
            this.setItems(val);
          }
        },
        {
          type: 'INPUT',
          label: '车主姓名',
          fieldName: 'indicatorName',
          initialValue: '',
          disabled: true,
          placeholder: '请输入',
          rules: [{ required: false, message: '请输入', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '证件类型',
          fieldName: 'indicatorCardType',
          initialValue: '',
          disabled: true,
          placeholder: '请选择',
          itemList: this.createDictList('1508'),
          rules: [{ required: false, message: '请选择', trigger: 'change' }],
          change: val => {
            if (val) {
              this.changeCardType(val, 2);
            }
          }
        },
        {
          type: 'INPUT',
          label: '证件号',
          fieldName: 'indicatorCardNo',
          initialValue: '',
          disabled: true,
          placeholder: '请输入',
          rules: [
            { required: false, message: '请输入', trigger: 'blur' },
            { trigger: 'blur', validator: banWord }
          ]
        },
        {
          type: 'INPUT',
          label: '企业名称',
          fieldName: 'indicatorEnterpriseName',
          initialValue: '',
          placeholder: '',
          disabled: true,
          rules: [{ required: false, message: '请输入', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '征信代码',
          fieldName: 'creditCode',
          initialValue: '',
          placeholder: '',
          disabled: true,
          offsetRightCols: 1,
          rules: [{ required: false, message: '请输入', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '家庭/企业地址',
          fieldName: 'address',
          initialValue: '',
          placeholder: '请输入',
          disabled: true,
          selfCols: 2
        },
        {
          type: 'INPUT',
          label: '邮政编码',
          fieldName: 'zipCode',
          initialValue: '',
          disabled: true,
          placeholder: ''
        }
      ];
    }
  }
};
</script>
